// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import axios from "axios";
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI);

/*axios请求拦截器*/
axios.interceptors.request.use(function (rs) {
    //获取本地存储的token
    const token = localStorage.getItem("token");
    //如果token不等于空
    if(token){
      //设置token到请求头部中
       rs.headers.Authorization=token;
    }
   return rs;
})
/*axios响应拦截器*/
axios.interceptors.response.use(function (rs) {
    console.log(rs.data);
    if(rs.data.code==301){
        self.$message(rs.data.msg);
        //回到登录页面
        self.$router.push("/");
    }
    if(rs.data.code==500){
      self.$alert(rs.data.msg);
    }
    //放行
    return rs;
})

/*设置axios模块默认访问的域名代理名称*/
axios.defaults.baseURL="/api";
/*定义请求体提的参数格式*/
axios.defaults.headers.post['Content-type'] ="application/json";
/*设置全局配置axios的变量为$http*/
Vue.prototype.$http = axios

Vue.config.productionTip = false


/* eslint-disable no-new */
const self =new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
